/*
 * Copyright (C) 2012 DataSymphony (http://datasymphony.com.au)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package au.com.ds.restty.ssl;

import org.apache.http.annotation.ThreadSafe;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;

/**
 * This factory creates a SchemeRegistry supporting SSL connections using self-signed certificates
 * Usage (spring):
 * 	<bean id="connManager"
 *		class="org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager"
 *		p:maxTotal="24" p:defaultMaxPerRoute="6">
 *		<constructor-arg>
 *			<bean class="au.com.ndm.common.ssl.EasySSLSchemeRegistryFactory"
 *				factory-method="createDefault" />
 *		</constructor-arg>
 *	</bean>
//			ClientConnectionManager connectinoMgr = new SingleClientConnManager(EasySSLSchemeRegistryFactory.createDefault());
//			mTransport = new ApacheHttpTransport(new DefaultHttpClient(connectinoMgr));
			
 *
 */

@ThreadSafe
public class EasySSLSchemeRegistryFactory {
	
    public static SchemeRegistry createDefault() {
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(
                new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
        registry.register(
                new Scheme("https", 443, new EasySSLSocketFactory()));
        return registry;
    }
    
}
